﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace UpFile
{
    public partial class UserLogin : Form
    {
        #region 用户-变量
        int userid;
        string username;
        string password;
        int branchid;
        string NAS_IP;
        #endregion

        public UserLogin()
        {
            InitializeComponent();
        }

        private void btn_login_Click(object sender, EventArgs e)
        {
            try
            {
                string strUserNmae = this.txtUserName.Text;
                string strPassWord = this.txtPW.Text.Trim(); //用户密码
                login.LoginSoapClient sever = new login.LoginSoapClient();
                string[] arry = new string[4];
                arry = sever.UserLogin(strUserNmae, strPassWord).ToArray();
                if (arry[0] == "1")
                {
                    userid = Convert.ToInt32(arry[1].ToString());
                    username = arry[2].ToString();
                    branchid = Convert.ToInt32(arry[3].ToString());
                    NAS_IP = arry[4].ToString();
                    if (NAS_IP.IndexOf("/") != -1)
                    {
                        NAS_IP = NAS_IP.Substring(0, NAS_IP.IndexOf("/"));
                    }
                    FileManage form = new FileManage(userid, username, branchid, NAS_IP);//通过调用文件管理构造函数传值(用户信息)
                    form.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("用户名或密码不存在！");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("登入失败！");
                return;
            }
            
        }

        private void UserLogin_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.ExitThread();
        }

    }
}
